package org.dromara.system.controller.miniyi;

import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.TimeUtil;
import org.dromara.system.domain.vo.ZServiceChartVO;
import org.dromara.system.mapper.ZServiceMapper;
import org.dromara.system.service.IZServiceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 邹城民意一张屏
 */
@RestController
@RequestMapping({"/zService"})
public class ZServiceController {
    private static final Logger log = LoggerFactory.getLogger(ZServiceController.class);
    @Autowired
    private ZServiceMapper zServiceMapper;
    @Autowired
    private IZServiceService izServiceService;

    /**
     * 高频柱状图
     *
     * @param timeCode  时间类型[1-当日,2-7天,3-30天,4-当前年份,5-全部,6-年月(6与开始时间，结束时间关联，其余1，2，3，4，5有参无影响)]
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @GetMapping({"hotProblem"})
    public R<List<ZServiceChartVO>> hotProblem(@RequestParam Integer timeCode,
                                               @RequestParam(defaultValue = "2022-01-01") String startTime,
                                               @RequestParam(defaultValue = "2022-01-15") String endTime) {
        log.info("[ZServiceController][hotProblem]enter, timeCode:{}, startTime:{}, endTime:{}", new Object[]{timeCode, startTime, endTime});
        String time = TimeUtil.buildTime(timeCode, startTime, endTime);
        List<ZServiceChartVO> zServiceList = this.izServiceService.getHotProblem(time);
        log.info("[ZServiceController][hotProblem]result:{}, timeCode:{}, startTime:{}, endTime:{}", new Object[]{zServiceList.size(), timeCode, startTime, endTime});
        return R.ok(zServiceList);
    }

    /**
     * 诉求类型
     *
     * @param timeCode  时间类型[1-当日,2-7天,3-30天,4-当前年份,5-全部,6-年月(6与开始时间，结束时间关联，其余1，2，3，4，5有参无影响)]
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @GetMapping({"appeal"})
    public R<List<ZServiceChartVO>> appeal(@RequestParam Integer timeCode,
                                           @RequestParam(defaultValue = "2022-01-01") String startTime,
                                           @RequestParam(defaultValue = "2022-01-15") String endTime) {
        log.info("[ZServiceController][appeal]enter, timeCode:{}, startTime:{}, endTime:{}", new Object[]{timeCode, startTime, endTime});
        String time = TimeUtil.buildTime(timeCode, startTime, endTime);
        List<ZServiceChartVO> zServiceList = this.zServiceMapper.getAppeal(time);
        log.info("[ZServiceController][appeal]result:{}, timeCode:{}, startTime:{}, endTime:{}", new Object[]{zServiceList.size(), timeCode, startTime, endTime});
        return R.ok(zServiceList);
    }

    /**
     * 工单问题分类--一级"
     *
     * @param timeCode  时间类型[1-当日,2-7天,3-30天,4-当前年份,5-全部,6-年月(6与开始时间，结束时间关联，其余1，2，3，4，5有参无影响)]
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @GetMapping({"levelOneProblem"})
    public R<List<ZServiceChartVO>> levelOneProblem(@RequestParam Integer timeCode,
                                                    @RequestParam(defaultValue = "2022-01-01") String startTime,
                                                    @RequestParam(defaultValue = "2022-01-15") String endTime) {
        String time = TimeUtil.buildTime(timeCode, startTime, endTime);
        List<ZServiceChartVO> zServiceList = izServiceService.getLevelOneProblem(time);
        return R.ok(zServiceList);
    }

    /**
     * 工单问题分类--二级
     *
     * @param timeCode      时间类型[1-当日,2-7天,3-30天,4-当前年份,5-全部,6-年月(6与开始时间，结束时间关联，其余1，2，3，4，5有参无影响)]
     * @param serQtypeName1 工单问题一级类型
     * @param startTime     开始时间
     * @param endTime       结束时间
     * @return
     */
    @GetMapping({"levelTwoProblem"})
    public R<List<ZServiceChartVO>> levelTwoProblem(@RequestParam Integer timeCode,
                                                    @RequestParam String serQtypeName1,
                                                    @RequestParam(defaultValue = "2022-01-01") String startTime,
                                                    @RequestParam(defaultValue = "2022-01-15") String endTime) {
        String time = TimeUtil.buildTime(timeCode, startTime, endTime);
        List<ZServiceChartVO> zServiceList = this.zServiceMapper.getLevelTwoProblem(time, serQtypeName1);
        return R.ok(zServiceList);
    }

    /**
     * 工单问题分类--三级
     *
     * @param timeCode      时间类型[1-当日,2-7天,3-30天,4-当前年份,5-全部,6-年月(6与开始时间，结束时间关联，其余1，2，3，4，5有参无影响)]
     * @param serQtypeName2 工单问题二级类型
     * @param startTime     开始时间
     * @param endTime       结束时间
     * @return
     */
    @GetMapping({"levelThreeProblem"})
    public R<List<ZServiceChartVO>> levelThreeProblem(@RequestParam Integer timeCode,
                                                      @RequestParam String serQtypeName2,
                                                      @RequestParam(defaultValue = "2022-01-01") String startTime,
                                                      @RequestParam(defaultValue = "2022-01-15") String endTime) {
        String time = TimeUtil.buildTime(timeCode, startTime, endTime);
        List<ZServiceChartVO> zServiceList = this.zServiceMapper.getLevelThreeProblem(time, serQtypeName2);
        return R.ok(zServiceList);
    }

    /**
     * 工单渠道各渠道数量
     *
     * @param timeCode  时间类型[1-当日,2-7天,3-30天,4-当前年份,5-全部,6-年月(6与开始时间，结束时间关联，其余1，2，3，4，5有参无影响)]
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @GetMapping({"appealChannels"})
    public R<Map<String, Integer>> appealChannels(@RequestParam Integer timeCode,
                                                  @RequestParam(defaultValue = "2022-01-01") String startTime,
                                                  @RequestParam(defaultValue = "2022-01-15") String endTime) {
        log.info("[ZServiceController][appealChannels]enter, timeCode:{}, startTime:{}, endTime:{}", new Object[]{timeCode, startTime, endTime});
        Map<String, Integer> zServiceList = this.izServiceService.getData(timeCode, startTime, endTime);
        return R.ok(zServiceList);
    }
}
